import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'package:toast/toast.dart';

class JIanceOrderPage extends StatefulWidget {
  final String oid;
  JIanceOrderPage(this.oid);

  @override
  _MyHomePageState createState() => new _MyHomePageState(this.oid);
}

class _MyHomePageState extends State<JIanceOrderPage> {
  List formList;
  Map orders = new Map();
  final String oid;
  _MyHomePageState(this.oid);
  initState() {
    super.initState();
    formList = [
      {
        "title": '客户姓名',
        'sub_title': '暂无',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '客户电话',
        'sub_title': '暂无',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '联系人',
        'sub_title': '暂无',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '联系电话',
        'sub_title': '暂无',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '预约时间',
        'sub_title': '暂无',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '检测地点',
        'sub_title': '暂无',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
    ];
    loaddata();
  }

  //加载数据
  loaddata() async {
    Map<String, String> map = new Map();
    map['oid'] = this.oid;
    //  SharedPreferences pref = await SharedPreferences.getInstance();
    //  map["id"]=pref.getString('uid');
    //  map["type"]="0";

    HttpHelper.post(HttpHelper.API_OrderDetail, (data) async {
      if (data != null) {
        if (data["code"].toString() == "1") {
          List oldlist = formList;
          var orderinfo = data["info"];
          for (var i = 0; i < oldlist.length; i++) {
            var item = oldlist[i];
            var str = "";
            if (i == 0)
              str = orderinfo["name"];
            else if (i == 1)
              str = orderinfo["phone_num"];
            else if (i == 2)
              str = orderinfo["name"];
            else if (i == 3)
              str = orderinfo["phone_num"];
            else if (i == 4)
              str = orderinfo["add_time"];
            else
              str = orderinfo["address"] + orderinfo["address"];

            item["sub_title"] = str;
          }

          setState(() {
            formList = oldlist;
            // orders=data["info"];
          });
          //pref.setStringList('userinfo', data["info"]);

        }
      }
    }, params: map);
  }

  Widget buildcontent() {
    List<Widget> tiles = [];
    Widget content;
    for (var item in formList) {
      tiles.add(Padding(
          padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
          child: Container(
              color: Colors.white,
              height: 50,
              child: new Row(
                children: <Widget>[
                  
                   new Padding(
                        padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                        child: new Text(
                          item['title'],
                          style: TextStyle(
                              fontSize: 15,
                              color: Color.fromRGBO(102, 102, 102, 1)),
                        )),
                  Expanded(

                    child:
                  new Padding(
                      padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                      child: 
                      Align(
                        alignment: Alignment.centerRight,
                        child:
                      new Text(
                        item['sub_title'],
                        style:
                            TextStyle(fontSize: 15, color: item['sub_color']),
                      )))),
                ],
              ))));
    }
    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text('订单信息'),
          backgroundColor: Colors.white,
          iconTheme: new IconThemeData(color: Colors.black),
          elevation: 0,
          // backgroundColor: Color.fromRGBO(255, 204, 48, 1),
        ),
        body: new Center(
            child: Container(
          decoration: new BoxDecoration(
            color: Color.fromRGBO(238, 238, 238, 1),
          ),
          child: Padding(
              padding: new EdgeInsets.fromLTRB(0, 10, 0, 0),
              child: new ListView(
                children: <Widget>[buildcontent()],
              )),
        )));
  }
}
